<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <el-form-item>
          <el-input v-model="query.keyword" placeholder="关键字"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="querySerch">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="exportExcel">导出</el-button>
        </el-form-item>
        <el-form-item label="" prop="resource">
          <el-col :span="12">
            <el-upload
                class="upload-demo"
                action="http://localhost:8080/shop/importExcel"
                list-type="picture">
              <el-button  type="primary">点击导入</el-button>
            </el-upload>
          </el-col>
        </el-form-item>
      </el-form>
    </el-col>
    <input type="button" value="注册" onclick="window.location.href='http://www.php.cn'">
    <el-table :data="pageData.data" highlight-current-row v-loading="listLoading" @selection-change="selsChange"
              style="width: 100%;">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-table :data="props.row.auditLogs" style="width: calc(100% - 47px)" class="two-list">
            <el-table-column type="selection" width="55">
            </el-table-column>
            <el-table-column type="index" width="60">
            </el-table-column>
            <el-table-column prop="state" label="状态">
              <template slot-scope="props">
							  <span v-if="props.row.state ==1">
								<span style="color:#00B46D">通过</span>
							  </span>
                <span v-else>
								<span style="color:#D75C89">驳回</span>
                 			 </span>
              </template>
            </el-table-column>
            <el-table-column prop="note" label="备注"></el-table-column>
            <el-table-column prop="auditManager.username" label="审核人员"></el-table-column>
            <el-table-column prop="audit_time" label="审核时间"></el-table-column>
          </el-table>
        </template>
      </el-table-column>
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column type="index" width="60">
      </el-table-column>
      <el-table-column prop="name" label="店铺名称" width="120" sortable>
      </el-table-column>
      <el-table-column prop="tel" label="联系电话" width="150" sortable>
      </el-table-column>
      <el-table-column prop="registerTime" label="注册时间" width="150" sortable>
      </el-table-column>
      <el-table-column prop="state" label="状态" width="80" sortable>
        <template scope="scope">
          <span v-if="scope.row.state==2" style="color: green">审核通过，待激活</span>
          <span v-if="scope.row.state==1" style="color: blue">待审核</span>
          <span v-if="scope.row.state==3" style="color: blue">已激活</span>
          <span v-if="scope.row.state==4" style="color: red">驳回</span>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="地址" min-width="120" sortable>
      </el-table-column>
      <el-table-column prop="logo" label="图标" min-width="180" sortable>
      </el-table-column>
      <el-table-column prop="employee.username" label="店长" min-width="80" sortable>
      </el-table-column>
      <el-table-column label="操作" width="250">
        <template scope="scope">
          <el-button size="small" @click="handleAudit(scope.row)">审核</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="审核店铺" :visible.sync="shopAuditVisible" :close-on-click-modal="false">
      <el-form :model="shopAuditLog" label-width="80px" ref="shopAuditLogForm">
        <el-form-item label="备注" prop="note">
          <el-input type="textarea" v-model="shopAuditLog.note"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="Cancel">取消</el-button>
        <el-button type="primary" @click.native="auditPass">通过</el-button>
        <el-button type="primary" @click.native="auditReject">驳回</el-button>
      </div>
    </el-dialog>

  </section>
</template>

<script>
/*	import util from '../../common/js/util'
	//import NProgress from 'nprogress'
	import { getUserListPage, removeUser, batchRemoveUser, editUser, addUser } from '../../api/api';*/

export default {
  data() {
    return {
      title: '',
      employees: [],
      filters: {
        name: ''
      },
      pageData: {
        total: 0,
        data: []
      },
      query: {
        currentPage: 1,
        pagesize: 5,
        keyword: ""
      },
      listLoading: false,
      sels: [],//列表选中列

      shopVisible: false,//编辑界面是否显示
      shopAuditVisible: false,//编辑界面是否显示
      shopLoading: false,
      shopFormRules: {
        name: [
          {required: true, message: '请输入店铺名称', trigger: 'blur'}
        ]
      },
      //编辑界面数据
      shopAuditLog: {
        id: null,
        note: ''
      },


    }
  },
  methods: {
    exportExcel(){
      location.href="http://localhost:8080/shop/exportExcel";
    },
    importExcel(){
    },
    /*取消*/
    Cancel() {
      this.shopAuditVisible=false
    },
    /*驳回*/
    auditReject() {
      this.$http.post("/shop/reject", this.shopAuditLog)
          .then(res => {
            if (res.data.success) {
              this.$message({
                message: res.data.msg,
                type: res.data.success
              });
            } else {
              this.$message({
                message: res.data.msg,
                type: res.data.success
              });
            }
            this.shopAuditVisible = false;
            this.getpagelist();
          })
    },
    /*通过*/
    auditPass() {
      this.$http.post("/shop/pass", this.shopAuditLog)
          .then(res => {
            if (res.data.success) {
              this.$message({
                message: res.data.msg,
                type: res.data.success
              });
            } else {
              this.$message({
                message: res.data.msg,
                type: res.data.success
              });
            }
            this.shopAuditVisible = false;
            this.getpagelist();
          })
    },
    //清除讲校验提示
    deleteBlurWarn() {
      this.shopVisible = false
    },
    //性别显示转换
    formatSex: function (row, column) {
      return row.sex == 1 ? '男' : row.sex == 0 ? '女' : '未知';
    },
    handleCurrentChange(currentPage) {
      this.query.currentPage = currentPage
      this.getpagelist();


  },
  selsChange: function (sels) {
    this.sels = sels;
  },
  //高级查询
  querySerch() {
    this.query.currentPage = 1
    this.getpagelist()
  },
  //获取所有用户
  getEmployees() {
    this.$http.get("/employee").then(res => {
      if (res) {
        this.employees = res.data
      }
    })
  },

  //获取分页列表店铺
  getpagelist() {
    console.log(this.query);
    this.$http.post("/shop", this.query).then(res => {
      console.log(res);
      this.pageData.data = res.data.query
      this.pageData.total = res.data.tatal
    })
  },
    handleAudit(row){
      this.shopAuditVisible=true
      this.shopAuditLog.id=row.id
    }
},
mounted()
{
  this.getpagelist();
}
}

</script>

<style scoped>

</style>